Skip to content

fix(reconciliation): explain broker-assisted fees and valuation basis - #496

Merged
Pigbibi merged 2 commits into
mainfrom
fix/reconciliation-fee-valuation-basis-20261101
Nov 1, 2026
Merged

Pigbibi merged 2 commits into
mainfrom
fix/reconciliation-fee-valuation-basis-20261101

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Grok Bot (an AI agent working for the repository owner) wrote the code, tests and documentation in this PR. It was not merged or deployed by the agent; human review is pending.

What changed

Replaces #495 with an identical tree on a clean branch cut from the current main. #495 could not merge because its first commit (409120b) fails the commitlint convention and the repo does not allow force-pushing a branch under review. The final tree equals #495 head 2786474 (git diff 2786474 HEAD is empty); the history is squashed into 2 Conventional Commits. #495 is closed and its branch is kept.

Problem: two Firstrade reconciliation differences (August 19.96 and total assets 0.06) were reported as unexplained. They come from the broker-assisted order fee (19.95) plus SEC Section 31 / FINRA TAF regulatory fees on margin-sellout sells, and from a price-basis difference between the balance API long_stock_value and summed position market values.

Behaviour after this PR:

  • Sells whose description contains BROKER/DEALER ORDER (including MARGIN SELLOUT) are split into broker-assisted fee, SEC fee and TAF. Unrounded fees are summed and rounded up to the cent with a 0.01 minimum; a residual within +/-0.01 is explained.
  • Rates live in an effective-dated schedule. TAF follows SR-FINRA-2026-021 (zero 2026-10-01 to 2026-12-31) and SR-FINRA-2026-020 (2027-2028 stay 0.000195/share, max 9.79; 2029 0.000232 / 11.61; 2030 and 2031 rows).
  • verified_through (2026-11-01) makes any later trade date unsupported, because the SEC FY2027 Section 31 rate is not published.
  • The CSV Date column is treated as the trade date (checked against EXEC TIME and S/D; the 8/28 IBIT row settles 8/31). Non-positive quantity or price is unsupported.
  • The balance-vs-positions difference is a separate valuation_basis_difference with tolerance min(max(0.10, 0.1% of market value), 25.00), an optional position-quantity cross-check, and unexplained for an empty positions list with a non-zero balance.
  • The collector keeps long_stock_value as its own fact; a conflicting value is flagged (long_stock_value_ambiguous) instead of failing the whole collection. The snapshot persists it only behind an explicit opt-in.

How verified

  • Tree check: git diff 2786474 HEAD is empty (tree d412136b4134), so the content is exactly what fix(reconciliation): explain broker-assisted fees and valuation basis #495 reviewed.
  • pytest tests/test_statement_reconciliation.py tests/test_account_facts_readonly.py tests/test_account_facts_publisher.py: 122 passed. ruff check (0.15.20, the locked version) passes on the whole repo excluding external.
  • commitlint 21.2.4 with config-conventional, run as in engineering-governance.yml over origin/main..HEAD: 0 problems on both commits. The PR title also passes.
  • The full suite cannot run locally (31 collection errors from a missing quant_platform_kit, the same on the base commit); CI runs it.
  • Regulatory facts were checked against the FINRA/SEC filings (Release 34-106410, 34-106409) and the SEC FY2026 Section 31 advisory. SR-FINRA-2026-020 is immediately effective but the SEC may still suspend it.
  • Not done: no Firstrade confirmations requested; statement PDFs not read; nothing deployed.

Supersedes #495.

Split broker-assisted sell and regulatory fees out of statement
reconciliation residuals using a dated Firstrade fee schedule, and
report the balances-versus-positions valuation basis difference
separately. The TAF increase is deferred to 2029 per SR-FINRA-2026-020.
Collect the balance-endpoint long_stock_value as a distinct fact. When
the top-level and result values conflict, withhold the value and mark it
ambiguous instead of discarding the whole collection. The publisher
persists it only when include_valuation_basis is enabled, because the
console schema does not yet accept the extra key.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 010cf560-e321-4a50-99d1-9b3edfed377b
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Pigbibi Pigbibi added the owner-approved Owner approval for high-risk PRs. AI agents must never apply this label. label Nov 1, 2026 — with Cursor
@Pigbibi
Pigbibi merged commit 68cc4d2 into main Nov 1, 2026
@Pigbibi
Pigbibi deleted the fix/reconciliation-fee-valuation-basis-20261101 branch November 1, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

owner-approved Owner approval for high-risk PRs. AI agents must never apply this label.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant